#include <bits/stdc++.h>

using namespace std;

map<long long,long long>mp1,mp2;

int main(){

    int n,a,b;scanf("%d%d%d",&n,&a,&b);
    long long x,y;
    for(int i=0;i<a;++i)
    {
        scanf("%lld%lld",&x,&y);
        mp1[x]=y;
    }
    for(int i=0;i<b;++i)
    {
        scanf("%lld%lld",&x,&y);
        mp2[x]=y;
    }
    long long ans=0;
    map<long long,long long>::iterator i=mp1.begin();
    map<long long,long long>::iterator j=mp2.begin();
    while(i!=mp1.end()&&j!=mp2.end())
    {
        if(i->first==j->first){
            ans+=i->second*j->second;
            i++;j++;
        }else if(i->first<j->first){
            i++;
        }else{
            j++;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

